#!/bin/bash

set -e

# El comando pexuga presenta.... a ....
# Dr. Pexuga y Camillero Pexuga
# En un   Script para  automatizar dsecargas ...
# 6/Jun/08

#VARS

URL=http://www.elitefreak.net/
FILE=index.html
DESTWEBFOLDER=/home/jr/web/
USERMLDONKEY=
PASSMLDONKEY=
OPC=" "

check_url(){

	clear
	wget $URL
}

check_links(){

	cat index.html | grep "A HREF=\"http://www.elitefreak.net/peliculas/" | cut -d '"' -f 2 | sort -ur > TEMPLINKS
	rm -f $FILE
}
check_ed2k(){

	cat TEMPLINKS |	while read line; do
		
		echo "$line"
		wget $line
		done

	cat *.htm | grep "ed2k" | cut -d '"' -f 2 | grep "ed2k://" > TEMPED2K
	rm -f *.htm
}

add_ed2k(){
	
	###
	### Deprecated... now ed2k added by ... .php
	###
	cat TEMPED2K | while read line; do

		NOM=`echo $line | cut -d '|' -f 3`	
		#echo "Quieres añadir ----->> $NOM       a Mldonkey?(s/n)"
		
		read -p "bien? " OPC
		echo "S/N"
		read OPCCC
		
		if [ "$OPC" = "s" ]; then
			mldonkey_command -u $USERMLDONKEY -p $PASSMLDONKEY $line
		fi
		done
	
}

eraser(){

	rm -f TEMPLINKS
	mv TEMPED2K $DESTWEBFOLDER

}




case "$1" in

	 *)
	check_url
	check_links
	check_ed2k
	#add_ed2k
	eraser

esac
